package net.cz.wc.command;

import java.sql.Connection;
import java.util.List;

import net.cz.wc.dao.SQLDao;
import net.cz.wc.data.ConnectionManager;
import net.cz.wc.olddto.OldLogDTO;
import net.cz.wc.output.ConsoleOutput;

/**
 * 
 * @author carloszuluaga
 *
 */
public class ListCommand implements Command {

	public void execute(String[] args) {
		System.out.println("ListCommand.execute()");
		
		Connection conn = null;
		
		ConsoleOutput.printDefaultHeader();
		
		try {
			conn = ConnectionManager.getConnection();
			conn.setAutoCommit(false);
			SQLDao dao = new SQLDao(conn);
			
			List<OldLogDTO> logList = dao.getLogs(null);
			
			ConsoleOutput.printDefaultLogHeader();
			
			for (OldLogDTO log: logList) {
				ConsoleOutput.printDefault(log);
			}
		} catch (Exception ee) {
			ee.printStackTrace();
		} finally {
			ConnectionManager.closeConnection(conn);
		}
	}
}
